package com.ssm.demo.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.demo.dao.TestMapper;
import com.ssm.demo.pojo.Test;
import com.ssm.demo.pojo.TestExample;
import com.ssm.demo.service.TestService;
import com.ssm.demo.util.PageBean;
import com.ssm.demo.util.global.GlobalException;
import com.ssm.demo.util.global.GlobalExceptionEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Zhang Yu
 * @description: TODO
 * @date 2024/3/27 7:23
 */
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    TestMapper testMapper;

    @Override
    public long countByExample(TestExample example) {
        return testMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(TestExample example) {
        return testMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return testMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Test record) {
        return testMapper.insert(record);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertSelective(Test record) {
        int result = testMapper.insertSelective(record);
        if (result > 0)
            return record.getId();
        return -1;
    }

    @Override
    public List<Test> selectByExample(TestExample example) {
        return testMapper.selectByExample(example);
    }

    @Override
    public Test selectByPrimaryKey(Integer id) {
        return testMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(Test record, TestExample example) {
        return testMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(Test record, TestExample example) {
        return testMapper.updateByExample(record, example);
    }

    @Override
    public int updateByPrimaryKeySelective(Test record) {
        return testMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Test record) {
        return testMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<Test> selectPager(PageBean pageBean) {
        List<Test> testList =  testMapper.selectAll();
        PageInfo<Test> pageInfo=new PageInfo<>(testList);
        return pageInfo;
    }

    @Override
    public String testException() {
        throw new GlobalException(GlobalExceptionEnum.REQUEST_PARAM_ERROR);
    }
}
